﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MockPrjTeam2.Biz;
using MockPrjTeam2.Entity;


namespace MockPrjTeam2.Pages.Views
{
    public partial class PopupSearchBussiness : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                ShowAllBussiness();
        }
        private void ShowAllBussiness()
        {
            var listBuss = new List<Bussiness>();
            var biz = new BussinessBiz();
            listBuss = biz.getAllBussinessByKey(string.Empty,string.Empty);
            GVSearchBussiness.DataSource = listBuss;
            GVSearchBussiness.DataBind();
        }
        protected void btSelect_Click(object sender, EventArgs e)
        {
            string selectedValue = Request.Form["MyRadioButton"];
            var buss = new Bussiness();
            var getbyId = new BussinessBiz();
            buss = getbyId.getById(Convert.ToInt32(selectedValue));
           
            txtBussName.Text = Convert.ToString(buss.BusinessName);
            txtSic.Text = Convert.ToString(buss.SicCode);
            hdnBussinessId.Value = Convert.ToString(buss.BusinessId);
            Session["Bussname"] = txtBussName.Text;
            Session["Sic"] = txtSic.Text;
            StringBuilder script = new StringBuilder();
            script.Append("<script type='text/javascript'>");
            script.AppendFormat("window.opener.document.getElementById('hdnBussId').value  = '{0}';",
                hdnBussinessId.Value);

            script.AppendFormat("window.opener.document.getElementById('txtBussinessName').value  = '{0}';",
                txtBussName.Text);
            script.AppendFormat("window.opener.document.getElementById('TxtSicCode').value  = '{0}';",
               txtSic.Text);



            script.Append("this.close();");
            script.Append("</script>");
            ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "key01", script.ToString(), false);
        }

        protected void btSearch_Click(object sender, EventArgs e)
        {
            var listType = new List<Bussiness>();
            var biz = new BussinessBiz();
            listType = biz.getAllBussinessByKey(Convert.ToString(txtBussName.Text), Convert.ToString(txtSic));
            if (listType != null)
            {
                GVSearchBussiness.DataSource = listType;
                GVSearchBussiness.DataBind();
            }    
        }
    }
}